<template>
	<view class="content">

		<!-- <image class="logo" src="../../static/xinlogo.png" mode=""></image> -->

		<view style="font-size: 35rpx; text-align: center; margin-top: 100rpx;">请选择您的班组信息: </view>

		<view class="xialakuang">
			<view class="shuruyhk">
				<view class="xzyhk">班组选择：</view>
				<uni-data-select class="xzkuang" v-model="valueUnion" :localdata="union" @change="change_union"
					placeholder="请选择班组" :clear="false">
				</uni-data-select>
			</view>
			<!-- <view class="shuruyhk" v-if="valueUnion != null && branch.length > 0">
				<view class="xzyhk">分会:</view>
				<uni-data-select class="xzkuang" v-model="valueBranch" :localdata="branch" @change="change_branch"
					placeholder="请选择分会" :clear="false">
				</uni-data-select>
			</view>
			<view class="shuruyhk" v-if="valueBranch != null && group.length > 0">
				<view class="xzyhk">班组:</view>
				<uni-data-select class="xzkuang" v-model="valueGroup" :localdata="group" @change="change_group"
					placeholder="请选择小组" :clear="false">
				</uni-data-select>
			</view> -->
		</view>

		<view class="tijiao" @click="submit">提 交</view>

	</view>
</template>

<script>
	let url = '/lgzhsys/teamlist'
	export default {
		data() {
			return {
				user: uni.getStorageSync("member"),
				union: [],
				valueUnion: null,
				branch: [],
				valueBranch: null,
				group: [],
				valueGroup: null,
				ultimatelyId: null,
			}
		},
		onLoad() {
			this.data_list();
		},
		methods: {
			data_list() {
				let self = this
				let data = {
					lessee_id: self.user.lessee_id
					// lessee_id: 17
				}
				self.branch = []
				self.valueBranch = null
				this.$boya.NGet(url, data, function(res) {

					let renamedTeams = res.data.map(team => ({
						name: team.workshop + ' - ' + team.team_name,
						...team, // 这里展开原对象，除了team_name键之外的其他键都会保持不变
					}));

					self.union = renamedTeams

					console.log('union：', self.union);
				})
			},
			change_union(e) {
				let self = this
				self.ultimatelyId = e
				console.log("e:", self.ultimatelyId);
			},
			// change_branch(e) {
			// 	let self = this
			// 	let data = {
			// 		id: e
			// 	}
			// 	self.group = []
			// 	self.valueGroup = null
			// 	this.$boya.NGet(url, data, function(res) {
			// 		console.log('group：', res);
			// 		if (res.data) {
			// 			self.group = res.data
			// 		} else {
			// 			self.group = []
			// 		}
			// 	})
			// 	self.ultimatelyId = e
			// 	console.log("e:", e);
			// },
			// change_group(e) {
			// 	let self = this
			// 	let data = {
			// 		id: e
			// 	}
			// 	// self.ultimatelyId = e
			// 	// self.group = []
			// 	// self.valueGroup = null
			// 	this.$boya.NGet(url, data, function(res) {
			// 		console.log('第4级：', res);
			// 	})
			// 	// self.ultimatelyId = e
			// 	console.log("e:", e);
			// },
			submit() {
				let self = this
				uni.showModal({
					title: '请注意！',
					content: '确定后不可更改，请问是否确定选择？',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中'
							});
							if (!self.ultimatelyId) {
								self.$boya.msg('您还未选择班组噢')
							} else {
								self.confirm();
							}
						} else if (res.cancel) {
							uni.showToast({
								title: '您已取消',
								duration: 2000,
								icon: 'none'
							});
						}
					}
				});
			},
			confirm() {
				let self = this
				console.log('班组id: ', self.ultimatelyId);
				let url = '/lgzhsys/set_team'
				let data = {
					"user_id": self.user.uuid, // 天拓用户id
					"team_id": self.ultimatelyId // 最后一级的id
				}
				uni.hideLoading();
				this.$boya.NPost(url, data, function(res) {
					console.log('tijiao: ', res);
					self.$boya.msg('提交成功')
					setTimeout(() => {
						uni.redirectTo({
							url: 'update_userinfo'
						})
					}, 1200)
				})
			}
		}
	}
</script>

<style>
	.content {
		width: 100%;
		height: 100%;
	}

	/* .logo {
		width: 230rpx;
		height: 60rpx;
		position: absolute;
		top: 20rpx;
		right: 20rpx;
	} */

	.xialakuang {
		width: 80%;
		margin: 0 auto;
		margin-top: 100rpx;
		/* border: 1px solid black; */
	}

	.shuruyhk {
		margin-top: 40rpx;
	}

	.xzyhk {
		font-size: 35rpx;
	}

	.xzkuang {
		width: 100%;
		height: 120rpx;
		margin-left: 20rpx;
	}

	.tijiao {
		width: 200rpx;
		margin: 0 auto;
		margin-top: 140rpx;
		height: 90rpx;
		text-align: center;
		line-height: 90rpx;
		font-size: 35rpx;
		border: 1px solid black;
		/* padding: 20rpx; */
		border-radius: 10rpx;
	}
</style>